#include "MenuItem.h"

MenuItem::MenuItem(string menuGroup, int width, int height, float top, float left, int zIndex, string text, void (*onClick)(MenuItem*)) {
	this->width = width;
	this->height = height;
	this->top = top;
	this->left = left;
	this->zIndex = (zIndex > 20)?20:zIndex;

	this->text = text;
	this->menuGroup = menuGroup;

	this->onClick = onClick;

	showing = false;

	this->FillQuad();
}

MenuItem::~MenuItem() {

}

/*
 * Public
 */

void MenuItem::SetShowing(bool showing) {
	this->showing = showing;
}

void MenuItem::SetColor(D3DXCOLOR color) {
	this->Quad[0].Color = color;
	this->Quad[1].Color = color;
	this->Quad[2].Color = color;
	this->Quad[3].Color = color;
}


/*
 * Private
 */

void MenuItem::FillQuad(void) {

	this->Quad[0].Color = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	this->Quad[1].Color = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	this->Quad[2].Color = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	this->Quad[3].Color = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);

	this->Quad[0].U = 0.0f;
	this->Quad[0].V = 0.0f;
		
	this->Quad[1].U = 1.0f;
	this->Quad[1].V = 0.0f;
		
	this->Quad[2].U = 0.0f;
	this->Quad[2].V = 1.0f;
		
	this->Quad[3].U = 1.0f;
	this->Quad[3].V = 1.0f;

	this->Quad[0].Z = 0.0f;
	this->Quad[1].Z = 0.0f;
	this->Quad[2].Z = 0.0f;
	this->Quad[3].Z = 0.0f;


	float top = this->top * 2.0f;
	float height = ((float)this->height / (float)windowSize.bottom) * 2.0f;

	float left = this->left * 2.0f;
	float width = ((float)this->width / (float)windowSize.right) * 2.0f;
	if(left < 0.0f) left = 1.0f - (width / 2.0f);


	this->Quad[0].X = -1.0f + left;
	this->Quad[0].Y = 1.0f - top;

	this->Quad[1].X = -1.0f + left + width;
	this->Quad[1].Y = 1.0f - top;

	this->Quad[2].X = -1.0f + left;
	this->Quad[2].Y = 1.0f - (top + height);

	this->Quad[3].X = -1.0f + left + width;
	this->Quad[3].Y = 1.0f - (top + height);
}